﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace D3DSS.IRepository
{
    /// <summary>
    /// 泛型仓储接口
    /// </summary>
    public interface IRepository<T> where T : class
    {
        /// <summary>
        /// 插入单条实体
        /// </summary>
        /// <param name="entity">实体</param>
        T Add(T entity);

        /// <summary>
        /// 获取单条实体
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        T Single(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 根据条件获取多条实体
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        List<T> Where(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 根据表达式判断实体是否存在
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        bool Exist(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        void Update(T entity);

        /// <summary>
        /// 根据表达式删除实体
        /// </summary>
        /// <param name="expression">表达式</param>
        void Delete(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 获取所有实体
        /// </summary>
        /// <returns></returns>
        List<T> All();

        /// <summary>
        /// 保存变更
        /// </summary>
        void SaveChanges();
    }
}
